package models;

import java.sql.Timestamp;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.OneToOne;

import ch.bfh.abcm.rems.sensors.tinkerforge.TFSensorType;
import play.db.jpa.Model;


@Entity
public class SensorData extends Model {

    private static final long serialVersionUID = 1L;
    
    private long timestamp;
    private int value;
    private String sensorUID;

    @OneToOne
    private TFSensorType sensorType;

    protected SensorData() {
    }

    public SensorData(int value, String sensorUID, TFSensorType sensorType) {
        this.sensorType = sensorType;
        this.sensorUID = sensorUID;
        this.value = value;
        this.timestamp = new Date().getTime();
    }

    public long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(long timestamp) {
        this.timestamp = timestamp;
    }

    public int getValue() {
        return value;
    }

    public void setValue(int value) {
        this.value = value;
    }

    public String getSensorUID() {
        return sensorUID;
    }

    public void setSensorUID(String sensorUID) {
        this.sensorUID = sensorUID;
    }

    public TFSensorType getSensorType() {
        return sensorType;
    }

    public void setSensorType(TFSensorType sensorType) {
        this.sensorType = sensorType;
    }

    public static SensorData saveSensorData(int value, String sensorUID, TFSensorType sensorType) {
        SensorData data = new SensorData(value, sensorUID, sensorType);
        data.save();
        return data;
    }
    
     public String toString() {
        return "SensorData: {Timestamp=" + new Timestamp(timestamp) + " value="+value+" UID=" + sensorUID + "}";
    }

}
